#ifndef CHARTTRAY_H
#define CHARTTRAY_H

#include <QWidget>
#include <QColor>
#include <QCursor>
#include <QPen>
#include <QBrush>
#include <QImage>
#include <QPolygon>

#include "defines.h"

class ChartTray : public QWidget {
 Q_OBJECT
public:
  ChartTray(QWidget *parent = 0);
  void draw(QPainter * painter);

  void   setVar(double newVal, int varName);
  double getVar(int varName);

  int typeTray() { return curChartType; };

public slots:
  void setType(int newType)    { curChartType = newType;	update(); };
  void setNumPart(int newNumPart) { numPart   = newNumPart+1;	update(); };
  void setAngle(int newVal)    { insAngle     = to_rad(newVal); update(); };
  void setB(double newVal)     { insB 	      = newVal;         update(); };
  void setH(double newVal)     { insH 	      = newVal;         update(); };
  void setHr(double newVal)    { insHr 	      = newVal;         update(); };
  void setHcr(double newVal)   { insHcr       = newVal;         update(); };
  void setHrain(double newVal) { insHrain     = newVal;         update(); };
  void setQ(double newVal)     { insQ 	      = newVal;         update(); };
  void setQr(double newVal)    { insQr 	      = newVal;         update(); };
  void setQcr(double newVal)   { insQcr       = newVal;         update(); };
  void setQrain(double newVal) { insQrain     = newVal;         update(); };
  void setVs(double newVal)    { insVs 	      = newVal;         update(); };
  void setVr(double newVal)    { insVr 	      = newVal;         update(); };
  void setVd(double newVal)    { insVd 	      = newVal;         update(); };

signals:
  void changeTrayType(int newTrayType);

protected:
  void paintEvent(QPaintEvent *event); 
  void mousePressEvent(QMouseEvent *event);
  // void mouseMoveEvent(QMouseEvent * event);

  void drawTray(QPainter * painter);
  void drawChartTypes(QPainter * painter);

  int curChartType;
  int numPart;

  double insAngle;
  double insB;
  double insH;
  double insHr;
  double insHcr;
  double insHrain;
  double insQ;
  double insQr;
  double insQcr;
  double insQrain;
  double insVs;
  double insVr;
  double insVd;

  bool isVisibleCR;
  bool isVisibleR;
  bool isVisibleREC;
  bool isVisibleRAIN;

  //Перевод угла в радианы
  double to_rad(int gr)    { return ((gr * PI) / 180); };
  //Перевод радиан в угол
  int to_gr(double rad)    { return ( int( (rad *180)/PI) ); };

  //Перевод реальных значений в пропорции
  int to_propoptions(double realVal, double L, int maxVal);
  //Перевод из пропорций в реальную величину
  double to_realVal(int propoptions, double L, int maxVal);

  //Убирает незначащие цифры после запятой
  double toPrec(double num) { double d = fmod(num, 0.01); return  num - d + double(rint(d * 1000))/1000; };

}; //class ChartTray : public QGraphicsView

#endif
